package com.syqc.adapter

import android.widget.TextView
import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.viewholder.BaseViewHolder
import com.syqc.comlib.MenuKey
import com.syqc.entity.FunInfo
import com.syqc.login.FunKey
import com.syqc.login.FunType
import com.syqc.monitor.R

class OperInfoAdapter(private val type: FunType) :
    BaseQuickAdapter<FunInfo, BaseViewHolder>(R.layout.item_oper_fun) {
    var isCanTalk = true
        set(value) {
            field = value
            notifyDataSetChanged()
        }

    override fun convert(holder: BaseViewHolder, item: FunInfo) {
        val tvFun = holder.getView<TextView>(R.id.tvFunction)
        tvFun.setText(getTextById(item.key))

        if (item.key == FunKey.FUN_Talk) {
            item.isCheckable = isCanTalk
            tvFun.isSelected = isCanTalk
        } else if (item.key == MenuKey.MENU_106) {
            if (type == FunType.CAR_MAP || type == FunType.POPUP) {
                item.isCheckable = false
                tvFun.isSelected = false
            } else {
                item.isCheckable = isCanTalk
                tvFun.isSelected = isCanTalk
            }
        } else {
            item.isCheckable = item.isCheckable
            tvFun.isSelected = item.isCheckable
        }
    }

    //
    fun getTextById(key: String): Int {
        return when (key) {
            MenuKey.MENU_106 -> R.string.fun_name_0
            FunKey.FUN_Talk -> R.string.fun_name_2
            MenuKey.MENU_104 -> R.string.fun_name_3
            MenuKey.MENU_917 -> R.string.fun_name_13
            MenuKey.MENU_229 -> R.string.fun_name_9
            MenuKey.MENU_201 -> R.string.fun_name_6
            MenuKey.MENU_912 -> R.string.fun_name_10
            MenuKey.MENU_916 -> R.string.fun_name_5
            MenuKey.MENU_103 -> R.string.fun_name_4
            MenuKey.MENU_204 -> R.string.fun_name_7
            MenuKey.MENU_902 -> R.string.fun_name_8
            MenuKey.MENU_907 -> R.string.fun_name_11
            MenuKey.MENU_908 -> R.string.fun_name_12
            MenuKey.MENU_903 -> R.string.fun_name_15
            FunKey.FUN_NAVI -> R.string.fun_name_14
            FunKey.FUN_CALL -> R.string.fun_name_16
            else -> R.string.desc_other
        }

    }
}